<?php
/**
 * Created by PhpStorm.
 * User: Digvijay
 * Date: 4/20/14
 * Time: 1:32 PM
 */

class Grade extends MY_Controller{
    function addGrade(){
        $id = trim($this->input->post('gradeId'));
        $name = trim($this->input->post('gradeName'));
        $grade = new SPGrade();
        if($id != "" && $id != null){
            $grade = $this->findById("SPGrade", $id);
        }
        $grade->setName($name);
        $this->save($grade);
        echo json_encode($this->findAll("SPGrade"));
    }

    function get($id = null){
        if($id == null){
            echo json_encode($this->findAll("SPGrade"));
        }else{
            echo json_encode($this->findById("SPGrade", $id));
        }

    }

    function delete($id = null){
        if($id != null){
            $grade = $this->findById("SPGrade", $id);
            parent::delete($grade);
            echo json_encode($this->findAll("SPGrade"));
        }
    }
} 